<?php
namespace Ygcl\Controller;
use Admin\Controller\AdminbaseController;
class RecordadminController extends AdminbaseController {
	
	protected $m;
	
	function _initialize() {
		parent::_initialize();
		$this->m = D('LessonRecord');
	}
	
    public function index(){    	
    	$this->display();
    }
    
    public function sigle(){
    	$this->display();
    }
    
    public function edit(){
    	$id = I('id');
    	if($id){
    		$this->info = $this->m->where(array('id'=>$id))->find();
    		$this->ctid = $this->info['ctid'];
    	}else{
    		$this->ctid = I('ctid');
    	}
    	$this->xueqi = R('Api/Term/get_term_infos_wgq');
    	$this->display();
    }
    
    public function edit_post(){
    	if(IS_POST){
    		//添加备注
    		$data_class = array(
    			'tid' => $_POST['tid'],
    			'remark' => $_POST['remark'],
    			'ctid' => $_POST['ctid'],
    			'update_time'=>Date('Y-m-d H:i:s'),
    		);
    		$id = $_POST['id'];
    		if($id){
    			$data_class['id'] = $id;
    			$this->m->create($data_class);
    			if($this->m->save()){
    				$this->success('保存成功');
    			}else{
    				$this->error('保存失败');
    			}
    		}else{
    			$data_class['create_time'] = $data_class['update_time'];
    			$this->m->create($data_class);
    			if($this->m->add()){
    				$this->success('添加成功');
    			}else{
    				$this->error('添加失败');
    			}
    		}
    	}
    }
    
    public function del(){
    	$id = array_unique((array)I('ids',0));
    	if ( empty($id) ) {
    		$this->error('请选择要操作的数据!');
    	}
    	$map = array('id' => array('in', $id));
    	$info = $this->m->where($map)->find();
    	if($this->m->where($map)->delete()){
    		$this->success('删除成功',U('index'));
    	} else {
    		$this->error('删除失败！');
    	}
    }
    
    public function changestatus(){
    	$data[$this->m->getPk()] = $_REQUEST['id'];
    	$data['status'] = $_REQUEST['status'];
    	$data['update_time'] = date('Y-m-d H:i:s');
    	if($this->m->save($data)){
    		$this->classService->_create_cache_class();
    		$this->success('状态更新成功');
    	}else{
    		$this->error('状态更新失败');
    	}
    }
}